package com.hjonline.sparkjob.demo.config;

import lombok.Data;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix="spark")
@Data
public class SparkContextBeanConfig
{
	
	private String sparkHome = ".";
	private String appName = "sparkTest";
	private String master = "local";
	
	@Bean
    @ConditionalOnMissingBean(SparkConf.class)
    public SparkConf sparkConf() throws Exception {
        SparkConf conf = new SparkConf()
                .setSparkHome(sparkHome)
                .setAppName(appName)
                .setMaster(master)
				.set("spark.executor.memory", "1g");
        return conf;
    }

    @Bean
    @ConditionalOnMissingBean(JavaSparkContext.class)
    public JavaSparkContext javaSparkContext() throws Exception {
       return new JavaSparkContext(sparkConf());
    }

//	public String getSparkHome() {
//		return sparkHome;
//	}
//
//	public void setSparkHome(String sparkHome) {
//		this.sparkHome = sparkHome;
//	}
//
//	public String getAppName() {
//		return appName;
//	}
//
//	public void setAppName(String appName) {
//		this.appName = appName;
//	}
//
//	public String getMaster() {
//		return master;
//	}
//
//	public void setMaster(String master) {
//		this.master = master;
//	}
}
